﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BitPortal.Models;
using BitPortal.Business;
using BitPortal.Utils;

namespace BitPortal.Services
{
    /// <summary>
    /// Summary description for KeywordList
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class KeywordList : System.Web.Services.WebService
    {
        [WebMethod]
        public List<Keyword> GetKeywordList(string start)
        {
            var list = (new ExtendedBitPortalEntities()).Keywords.ToList();
            return (from ent in list
                    where ent.KeyName.StartsWith(start, StringComparison.OrdinalIgnoreCase) || ent.NoneUnicodeValue.StartsWith(start, StringComparison.OrdinalIgnoreCase)
                    orderby ent.SortOrder descending , ent.SearchCount descending, ent.ResultCount descending
                    select ent).Take(10).ToList();
        }
    }
}
